// Replication for "Civil Conflict Fragmentation and the Effectiveness of UN Peacekeeping Operations", International Peacekeeping, 2020
// Baris Ari and Theodora-Ismene Gizelis
// May 2020

use "duration.dta", clear

set more off
stset date1, id(ConflictEp) time0(date0) origin(time date0) failure(EpEnd==1) exit(time .)

global MINIMAL i.Incomp rgdppc_ln pop_ln v2x_polyarchy BdBestTotal_cum_ln i.Resources 
global ADDITIONAL RebExpSup i.Region cinc i.TypeOfConflict

// Model 1
stcox Fractionalization $MINIMAL if UNPKO != . , nohr efron cluster(ConflictId)

// Model 2
stcox Fractionalization UNPKO $MINIMAL if UNPKO != . , nohr efron cluster(ConflictId)

// Model 3
stcox c.Fractionalization##i.UNPKO $MINIMAL if UNPKO != . , nohr efron cluster(ConflictId)

// Model 4
stcox c.Fractionalization##i.UNPKO $MINIMAL  $ADDITIONAL if UNPKO != . , nohr efron cluster(ConflictId)

// Model 5 
stcox c.GroupNo##c.UNPKO $MINIMAL  $ADDITIONAL if UNPKO != . , nohr efron cluster(ConflictId)

// Figure 2: Hazard Ratio graph
gen Interaction = Fractionalization * UNPKO
stcox c.Fractionalization i.UNPKO Interaction $MINIMAL  $ADDITIONAL if UNPKO != . , efron cluster(ConflictId)

lincom Fractionalization + 0 * Interaction
lincom Fractionalization + 0 * Interaction, level(99)

lincom Fractionalization + 1 * Fractionalization
lincom Fractionalization + 1 * Interaction, level(99)

// Figure 3: Main Graph
set more off
stcox c.Fractionalization##c.UNPKO  $MINIMAL  $ADDITIONAL if UNPKO != . , nohr efron cluster(ConflictId)
global Options xlabel(365 1825 3285) xtitle("") title("") ytitle("") range(0 3285) graphregion(color(white)) legend(order(1 "UN PKO" 2 "No UN PKO")) ylabel(0(0.25)1, nogrid) 
stcurve, survival at1(UNPKO = 1 Fraction = 0   )   at2(UNPKO = 0 Fraction = 0  ) $Options name(g1 , replace) t1("CFI = 0") lwidth("thick" "thick") lpattern("--" "l") lcolor("black" "black")
stcurve, survival at1(UNPKO = 1 Fraction = 0.4 ) at2(UNPKO = 0 Fraction = 0.4 )  $Options name(g2 , replace) t1("CFI = 0.4") lwidth("thick" "thick") lpattern("--" "l") lcolor("black" "black")
grc1leg g1 g2, l1(Survival Rate) b1(Conflict Days) graphregion(color(white)) title("Predicted Survival Functions (Model 4)")

